<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: 雷楚桥
  Date: 2018-06-13
  Time: 18:42
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>


<div class="layui-fluid">
    <div class="layui-card">

        <div class="layui-card-header"  style="color:#d02e25;font-family: '楷体'; ">
            成绩信息
        </div>

        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item refresh-nav" align="center">
                <div class="layui-inline">
                    <label class="layui-form-label">序号</label>
                    <div class="layui-input-inline">
                        <input type="text" name="green_house_name" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">姓名</label>
                    <div class="layui-input-inline">
                        <input type="text" name="master_name" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn" data-type="reload">搜索</button>
                </div>
            </div>
            <div class="layui-card-body">
                <table id="cropStatusList" lay-filter="cropStatusList"></table>
            </div>
        </div>
    </div>

    <script>
        layui.use(['table','form'], function(){
            var table = layui.table
                ,form = layui.form;

            //农资列表
            table.render({
                elem: '#cropStatusList'
                // ,height: 'full-200'
                ,method: 'post'
                ,url: '/ajax/party/fore/info'
                ,page: true
                ,loading: true
                ,cellMinWidth: 80
                ,limit: 20
                ,id: 'cropStatusList'
                ,cols: [[
                    {field: 'id', title: '序号', width: 100, sort: true, fixed: 'left'}
                    ,{field: 'greenHouseName', title: '姓名 '}
                    ,{field: 'greenHouseMain', title: '学期',width:250}
                    ,{field: 'masterName', title: '所属党组织'}
                    ,{field: 'note', title: '成绩 '}
                    ,{fixed: 'right', title: '操作', align: 'center', width: 120, toolbar: '#dothing' }
                ]]
            });

            //监听工具条
            table.on('tool(cropStatusList)', function(obj){
                var data = obj.data;

                if(obj.event === 'detail'){

                    $.post('/ajax/getCropStatus',{
                        id:data.id
                    },function(result){
                        layer.open({
                            type: 1,
                            area: ['1000px','80%'],
                            title: "ID:" + data.id,
                            offset: '10%',
                            anim: 4,
                            shadeClose: true,
                            content: $("#show-detail").html()
                        });
                        update_form_value(result);
                    });
                } else if(obj.event === 'del'){
                    layer.confirm('真的删除行么', function(index){
                        $.post("/ajax/deleteCropStatus",{
                            id:data.id
                        },function(result){
                            console.log(result);
                            obj.del();
                            layer.close(index);
                        });
                    });
                } else if(obj.event === 'edit'){
                    layer.alert('编辑行：<br>'+ JSON.stringify(data))
                }else if(obj.event === 'place'){
                    refresh("/fore/place",{
                        cropStatusId:data.id
                    });
                }
            });

            //执行重载
            var $ = layui.$, active = {
                reload: function(){

                    //执行重载
                    table.reload('cropStatusList', {
                        page: {
                            curr: 1
                        }
                        ,where: {
                            greenHouseName: $('.refresh-nav input[name=green_house_name]').val(),
                            masterName: $('.refresh-nav input[name=master_name]').val(),
                            cropName: $('.refresh-nav input[name=crop_name]').val()
                        }
                    });
                }
            };

            //搜索刷新
            $('.refresh-nav .layui-btn').on('click', function(){
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });


            <%--新增农资--%>
            $(".add-crop-status").click(function(){
                refresh("/admin/addList");
            });



            //更新
            function update_form_value(data){
                $("input[name=greenHouseName]").val(data.greenHouse.name);
                $("input[name=greenHouseAlias]").val(data.greenHouse.alias);
                $("input[name=greenHouseDescription]").val(data.greenHouse.description);
                $("input[name=greenHouseMain]").val(data.greenHouse.main);


                $("input[name=userName]").val(data.user.name);
                $("input[name=userAge]").val(data.user.age);
                $("input[name=userTownName]").val(data.userTownName);
                $("input[name=userVillageName]").val(data.userVillageName);
                $("input[name=userIdCard]").val(data.user.idCard);
                $("input[name=userHealthStatus]").val(userHealthStatus[data.user.healthStatus]);

                $("input[name=userNation]").val(userNation[data.user.nation]);
                $("input[name=userUpdateTime]").val(data.user.updateTime);


                $("input[name=cropName]").val(data.crop.name);
                $("input[name=cropCategory]").val(data.crop.category);
                $("textarea[name=cropSynopsis]").val(data.crop.synopsis);


                $("input[name=stepName]").val(data.cropStatus.stepName);
                $("input[name=healthName]").val(data.cropStatus.healthName);

            }
        });
    </script>

    <script type="text/html" id="dothing">
        <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">删除</a>
        <%--<c:if test="${userInfo != null}">--%>
        <%--<a class="layui-btn layui-btn-xs" lay-event="place">下单</a>--%>
        <%--</c:if>--%>
        <%--<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>--%>
        <%--<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>--%>
    </script>
    <script type="text/html" id="cropUrlShow">
        <img src="/static/upload/{{d.cropUrlShow}}" style="height:48px;width:48px;line-height:48px!important;"/>
    </script>
</div>